<template>
  <div class="app-container">
    <el-descriptions title="监控与通信设施————清洁频率">
      <el-descriptions-item label="一级养护建议清洁频率">1次/季度</el-descriptions-item>
      <el-descriptions-item label="二级养护建议清洁频率">1次/半年</el-descriptions-item>
      <el-descriptions-item label="三级养护建议清洁频率">1次/年</el-descriptions-item>
    </el-descriptions>
    <hr>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隧道名称" prop="field1">
        <el-select v-model="queryParams.field1" placeholder="请选择隧道名称" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in suidaoList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备名称" prop="field2">
        <el-input
          v-model="queryParams.field2"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <br>
      <el-form-item label="养护等级">
        <el-input
          v-model="level"
          placeholder="隧道养护等级"
          clearable
          disabled=""
          size="small"
          @keyup.enter.native="handleQuery2"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery2">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:jidianjiankongyutongxinqingjie:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          v-if="false"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:jidianjiankongyutongxinqingjie:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:jidianjiankongyutongxinqingjie:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['biz:jidianjiankongyutongxinqingjie:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jidianjiankongyutongxinqingjieList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="清洁维护单号" align="center" prop="id" />
      <el-table-column label="隧道名称" align="center" prop="field1" />
      <el-table-column label="设备名称" align="center" prop="field2" />
      <el-table-column label="养护机构" align="center" prop="field3" />
      <el-table-column label="养护日期" align="center" prop="field4" />
      <el-table-column label="养护措施" align="center" prop="field5" />
      <el-table-column label="养护人员" align="center" prop="field6" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:jidianjiankongyutongxinqingjie:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:jidianjiankongyutongxinqingjie:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="隧道名称" prop="field1">
          <el-select v-model="form.field1" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.id + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备名称" prop="field2">
          <el-select v-model="form.field2" placeholder="请选择设备名称">
            <el-option
              v-for="item in shebeiName"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="养护机构" prop="field3">
          <el-input v-model="form.field3" placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="养护日期" prop="field4">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field4"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择养护日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护措施" prop="field5">
          <el-input v-model="form.field5" placeholder="请输入养护措施" />
        </el-form-item>
        <el-form-item label="养护人员" prop="field6">
          <el-input v-model="form.field6" placeholder="请输入养护人员" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { getlevelByTunnelName,
  listJidianjiankongyutongxinqingjie,
  getJidianjiankongyutongxinqingjie,
  delJidianjiankongyutongxinqingjie,
  addJidianjiankongyutongxinqingjie,
  updateJidianjiankongyutongxinqingjie,
  exportJidianjiankongyutongxinqingjie
} from "@/api/biz/jidianjiankongyutongxinqingjie";
import { listSuidao } from "@/api/biz/suidao";

export default {
  name: "Jidianjiankongyutongxinqingjie",
  data() {
    return {
      shebeiName:[
        {
          value: '亮度检测器(50100)',
          label: '亮度检测器(50100)'
        }, {
          value: '能见度检测器(50200)',
          label: '能见度检测器(50200)'
        }, {
          value: 'CO检测器(50300)',
          label: 'CO检测器(50300)'
        }, {
          value: '风速风向检测器(50400)',
          label: '风速风向检测器(50400)'
        }, {
          value: '车辆检测器(50500)',
          label: '车辆检测器(50500)'
        }, {
          value: '闭路电视——摄像机(50601)',
          label: '闭路电视——摄像机(50601)'
        }, {
          value: '闭路电视——编解码器(50602)',
          label: '闭路电视——编解码器(50602)'
        }, {
          value: '闭路电视——视频矩阵(50603)',
          label: '闭路电视——视频矩阵(50603)'
        }, {
          value: '闭路电视——监视器(50604)',
          label: '闭路电视——监视器(50604)'
        }, {
          value: '闭路电视——硬盘录像机(50605)',
          label: '闭路电视——硬盘录像机(50605)'
        }, {
          value: '其他闭路电视设施(50699)',
          label: '其他闭路电视设施(50699)'
        }, {
          value: '视频交通事件检测器(50700)',
          label: '视频交通事件检测器(50700)'
        }, {
          value: '紧急电话及广播(51000)',
          label: '紧急电话及广播(51000)'
        }, {
          value: '本地控制器(51100)',
          label: '本地控制器(51100)'
        }, {
          value: '横通道门(51200)',
          label: '横通道门(51200)'
        }, {
          value: '横通道控制箱(51300)',
          label: '横通道控制箱(51300)'
        }, {
          value: '可变信息标志(51401)',
          label: '可变信息标志(51401)'
        }, {
          value: '可变限速标志(51402)',
          label: '可变限速标志(51402)'
        }, {
          value: '车道指示器(51403)',
          label: '车道指示器(51403)'
        }, {
          value: '交通信号灯(51404)',
          label: '交通信号灯(51404)'
        }, {
          value: '光端机(51502)',
          label: '光端机(51502)'
        }, {
          value: '路由器、交换机(51503)',
          label: '路由器、交换机(51503)'
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      level: null,
      suidaoList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      jidianjiankongyutongxinqingjieList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        field1: [
          { required: true, message: "隧道名称不能为空", trigger: "blur" },
        ],
        field2: [
          { required: true, message: "设备名称不能为空", trigger: "blur" },
        ],
        field3: [
          { required: true, message: "养护机构不能为空", trigger: "blur" },
        ],
        field4: [
          { required: true, message: "养护日期不能为空", trigger: "blur" },
        ],
        field5: [
          { required: true, message: "养护措施不能为空", trigger: "blur" },
        ],
        field6: [
          { required: true, message: "养护人员不能为空", trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listJidianjiankongyutongxinqingjie(this.queryParams).then(response => {
        this.jidianjiankongyutongxinqingjieList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuery2() {
      this.queryParams.pageNum = 1;
      getlevelByTunnelName(this.queryParams).then(response => {
        this.level = response.rows[0];
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetQuery2() {
      this.level=null;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getJidianjiankongyutongxinqingjie(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateJidianjiankongyutongxinqingjie(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJidianjiankongyutongxinqingjie(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function() {
        return delJidianjiankongyutongxinqingjie(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有清洁记录数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportJidianjiankongyutongxinqingjie(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  }
};
</script>
